#include <gtest/gtest.h>
#include <vector>

using namespace ::std;

class Solution {
public:
    int maxArea(vector<int>& height);
    int cntArea(vector<int>& height, int left, int right);
};

int Solution::maxArea(vector<int>& height) {
    int size = height.size();
    int maxArea = 0; // 保存最大面积
    for(int i = 0; i < size; ++i) {
        for(int j = i + 1; j < size; ++j) {
            int currentArea = cntArea(height, i, j);
            if(currentArea > maxArea) maxArea = currentArea;
        }
    }
    return maxArea;
}

int Solution::cntArea(vector<int>& height, int left, int right) {
    return (right - left) * (height[left] < height[right] ? height[left] : height[right]);
}

class MaxAreaCheck : public ::testing::Test {
public:
	class Solution solution;
};

TEST_F(MaxAreaCheck, testMaxArea_1) {
    vector<int> height = {1,8,6,2,5,4,8,3,7};
    EXPECT_TRUE(49 == solution.maxArea(height));
}

TEST_F(MaxAreaCheck, testMaxArea_2) {
    vector<int> height = {1,8,6,2,5,9,10,6,4,8,3,7};
    EXPECT_TRUE(70 == solution.maxArea(height));
}

TEST_F(MaxAreaCheck, testMaxArea_3) {
    vector<int> height = {1,1};
    EXPECT_TRUE(1 == solution.maxArea(height));
}

TEST_F(MaxAreaCheck, testMaxArea_4) {
    vector<int> height = {0,1,0};
    EXPECT_TRUE(0 == solution.maxArea(height));
}

TEST_F(MaxAreaCheck, testMaxArea_5) {
    vector<int> height = {2,0};
    EXPECT_TRUE(0 == solution.maxArea(height));
}

int main() {
	::testing::InitGoogleTest();
	return RUN_ALL_TESTS();
}
